<template>
  <div class="hello">
    <div v-if="type === '1'" @click="goBack">
      <i class="el-icon-arrow-left">返回上一级</i>
    </div>
    <div class="main">
      <ul class="listTitle">
        <li>项目名称</li>
        <li>测试结果</li>
        <li>测试成绩</li>
        <li v-if="type === '1'">操作</li>
      </ul>
      <div class="dataList">
        <ul v-for="(item, index) in tableData" class="list" :key="index">
          <li>{{ item.type }}</li>
          <li>{{ item.content }}</li>
          <li>{{ item.teacherevaluate }}</li>
          <li v-if="type === '1'">
            <el-button size="mini" type="primary" @click="edit(item)"
              >编辑</el-button
            >
            <!-- <el-button size="mini" type="warning">删除</el-button> -->
          </li>
        </ul>
      </div>
    </div>
    <editDataInfoDialog
      ref="openDialog"
      :formLabelAlign="dataInfo"
      :dataId="dataId"
      @editScore="editScore"
    />
  </div>
</template>

<script>
import { mapState } from "vuex";
import axios from "axios";
import editDataInfoDialog from "./editDataInfoDialog";
export default {
  components: {
    editDataInfoDialog,
  },
  data() {
    return {
      tableData: [],
      dataInfo: {},
      dataId: "",
    };
  },
  methods: {
    postAxios: function () {
      // let studentid=this.$route.query.roleid;//必通过query传参

      let ind = localStorage.getItem("lx");
      console.log("ind", ind);
      let studentid = localStorage.getItem("yh");
      if (ind == "1") {
        studentid = localStorage.getItem("belonger");
        console.log("studentid", studentid);
      } else if (ind == "2") {
        studentid = localStorage.getItem("yh"); //必通过query传参
      }

      console.log(studentid + "++++");
      axios
        .post("/api/user/showtablerecord", {})
        .then((response) => {
          var newArr = response.data.filter((item) => {
            if (studentid === item.belonger) {
              return true;
            }
          });
          console.log(newArr);
          this.tableData = newArr;
          //console.log('姓名:  '+this.stus[0].name);
        })
        .catch((error) => {
          console.log(error);
        });
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    goBack() {
      this.$emit("goback", false);
      // location.reload()
    },

    edit(item) {
      this.dataInfo = {
        name: item.type,
        result: item.content,
        score: item.teacherevaluate,
      };
      this.dataId = item.belonger;
      this.$refs.openDialog.openDialog();
    },
    editScore(e) {
      this.tableData = e;
    },
  },

  computed: mapState({
    type(state) {
      return state.app.type;
    },
  }),
  created() {
    this.postAxios();
    //this.postAxiosrecord();
    console.log("--------------------------");
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.hello {
  /deep/.el-button {
    position: static !important;
  }
  .main {
    margin-top: 20px;
  }
  ul {
    list-style: none;
  }
  text-align: left;
  padding: 20px;
  box-sizing: border-box;
  .listTitle {
    width: 100%;
    display: flex;
    font-size: 18px;
    li {
      width: 20%;
      text-align: center;
      margin: 0 10px;
      // margin: 2px 8% 10px;
    }
  }
  .dataList {
    width: 100%;
    padding-top: 20px;
    padding-left: 4px;
    box-sizing: border-box;
    .list {
      width: 100%;
      display: flex;
      border-bottom: 1px dashed #aaa;
      li {
        width: 20%;
        margin: 10px;
        // background: brown;
        text-align: center;
      }
    }
  }
}
</style>
